package com.bkgy.modularbx.slip.entity;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.io.IOException;

/**
 * 加载配置文件
 */
@Configuration
@EnableScheduling
public class SlipDetectionConfig {

    @Value("${slip.detection.config.path:/config/roll-mapping-config.json}")
    private String configPath;

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper();
    }

    /**
     * 加载 接口数据转映射文件 并转化为实体配置
     * @return
     * @throws IOException
     */
    @Bean
    public RollMappingConfiguration loadRollMappingConfig() throws IOException {
        //Resource resource = new ClassPathResource(configPath);
        Resource resource = new ClassPathResource(configPath);
        return objectMapper().readValue(resource.getInputStream(), RollMappingConfiguration.class);
    }
}